<script setup lang="ts">
import { reactive, ref, onMounted } from "vue";
import CountUp from "@/components/count-up";
import BarLeft from "@/components/bar-left/index.vue";
const duration = ref(2);
const state = reactive({
  alarmNum: 759,
  offlineNum: 44,
  onlineNum: 654,
  totalNum: 698,
});

// 响应式数据
const loading = ref(false)

// 使用备用数据
const useBackupData = () => {
    // 保持原有的模拟数据
}

// const getData = () => {
//     console.log(res);
//     if (res.success) {
//       state.alarmNum = res.data.alarmNum;
//       state.offlineNum = res.data.offlineNum;
//       state.onlineNum = res.data.onlineNum;
//       state.totalNum = res.data.totalNum;
//     }
// };
const progressData = ref([
    {
        name: '三农中心',
        value: 0,
        color: 'linear-gradient(90deg, #7CBDCF 0%, #5287DE 100%)',
        type: 1,
        valueB: 100
    },
    {
        name: '物流园',
        value: 0,
        color: 'linear-gradient(90deg, #7CBDCF 0%, #5287DE 100%)',
        type: 1,
        valueB: 100
    },
    {
        name: '党校',
        value: 0,
        color: 'linear-gradient(90deg, #7CBDCF 0%, #5287DE 100%)',
        type: 1,
        valueB: 100
    },
    {
        name: '环保局',
        value: 0,
        color: 'linear-gradient(90deg, #7CBDCF 0%, #5287DE 100%)',
        type: 1,
        valueB: 100
    },
    // { name: '绿电消纳总量', value: 90, color: 'linear-gradient(90deg, #7CBDCF 0%, #5287DE 100%)', type: 2 }
])
// getData();

// 组件挂载时获取数据
onMounted(async () => {
    // await fetchConsumptionRankingData()
})

const init = (data: any) => {
  let obj = JSON.parse(data)
  progressData.value.forEach((item: any) => {
    item.valueB = Number(obj.agriculture) + Number(obj.logistics) + Number(obj.party) + Number(obj.env)

    if(item.name == '三农中心'){
      item.value = Number(obj.agriculture)
    }
    if(item.name == '物流园'){
      item.value = Number(obj.logistics)
    }
    if(item.name == '党校'){
      item.value = Number(obj.party)
    }
    if(item.name == '环保局'){
      item.value = Number(obj.env)
    }
  })
}

defineExpose({
  init
})
</script>

<template>
  <!-- <ul class="user_Overview flex">
    <li class="user_Overview-item" style="color: #00fdfa">
      <div class="user_Overview_nums allnum">
        <CountUp :endVal="state.totalNum" :duration="duration" />
      </div>
      <p>短视频总数</p>
    </li>
    <li class="user_Overview-item" style="color: #07f7a8">
      <div class="user_Overview_nums online">
        <CountUp :endVal="state.onlineNum" :duration="duration" />
      </div>
      <p>抖音</p>
    </li>
    <li class="user_Overview-item" style="color: #e3b337">
      <div class="user_Overview_nums offline">
        <CountUp :endVal="state.offlineNum" :duration="duration" />
      </div>
      <p>小红书</p>
    </li>
    <li class="user_Overview-item" style="color: #f5023d">
      <div class="user_Overview_nums laramnum">
        <CountUp :endVal="state.alarmNum" :duration="duration" />
      </div>
      <p>蝴蝶号</p>
    </li>
  </ul> -->
  <BarLeft :progressData="progressData" style="width: 100%;height: 100%;padding-bottom: 40px;"></BarLeft>
</template>

<style scoped lang="less">
.left-top {
  width: 100%;
  height: 100%;
}

.user_Overview {
  li {
    flex: 1;

    p {
      text-align: center;
      height: 16px;
      font-size: 16px;
    }

    .user_Overview_nums {
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      font-size: 22px;
      margin: 50px auto 30px;
      background-size: cover;
      background-position: center center;
      position: relative;

      &::before {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
      }

      &.bgdonghua::before {
        animation: rotating 14s linear infinite;
      }
    }

    .allnum {
      &::before {
        background-image: url("@/assets/img/left_top_lan.png");
      }
    }

    .online {
      &::before {
        background-image: url("@/assets/img/left_top_lv.png");
      }
    }

    .offline {
      &::before {
        background-image: url("@/assets/img/left_top_huang.png");
      }
    }

    .laramnum {
      &::before {
        background-image: url("@/assets/img/left_top_hong.png");
      }
    }
  }
}
</style>
